package com.ruoyi.business.controller;

import com.ruoyi.business.service.IWsdSuggestionsService;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.domain.entity.SysUser;
import com.ruoyi.common.core.domain.entity.WsdSuggestions;
import com.ruoyi.common.core.domain.vo.WsdSuggestionsVO;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
import javax.servlet.http.HttpServletResponse;
import java.util.ArrayList;
import java.util.List;

/**
 * 用于记录投诉和建议的信息Controller
 *
 * @author ruoyi
 * @date 2024-04-19
 */
@RestController
@RequestMapping("wsd_suggestions")
public class WsdSuggestionsController extends BaseController {
    @Autowired
    private IWsdSuggestionsService wsdSuggestionsService;

    /**
     * 查询用于记录投诉和建议的信息列表
     */
    @PreAuthorize("@ss.hasPermi('business:suggestions:list')")
    @GetMapping("/list")
    public TableDataInfo list(WsdSuggestions wsdSuggestions) {
        startPage();
        List<WsdSuggestions> list = wsdSuggestionsService.selectWsdSuggestionsList(wsdSuggestions);
        for (WsdSuggestions wsdSuggestions1 : list){
            if (wsdSuggestions1.getImageUrl()!=null&&!"".equals(wsdSuggestions1.getImageUrl())) {
                // 创建两个列表，用于存储分割后的图片和证书信息
                List<String> imagesList = new ArrayList<>();
                if (wsdSuggestions1.getImageUrl().contains("||")) {
                    // 使用"||"作为分隔符分割图片信息字符串
                    String[] images = wsdSuggestions1.getImageUrl().split( "\\|\\|" );
                    for (String image : images) {
                        imagesList.add( image );
                    }
                }else {
                    imagesList.add( wsdSuggestions1.getImageUrl() );
                }
                // 设置CompanyVO对象的图片列表和证书列表
                wsdSuggestions1.setImageUrls( imagesList );
            }
        }
        return getDataTable(list);
    }

    /**
     * 导出用于记录投诉和建议的信息列表
     */
    @PreAuthorize("@ss.hasPermi('business:suggestions:export')")
    @Log(title = "用于记录投诉和建议的信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, WsdSuggestions wsdSuggestions) {
        List<WsdSuggestions> list = wsdSuggestionsService.selectWsdSuggestionsList(wsdSuggestions);
        ExcelUtil<WsdSuggestions> util = new ExcelUtil<WsdSuggestions>(WsdSuggestions.class);
        util.exportExcel(response, list, "用于记录投诉和建议的信息数据");
    }

    /**
     * 获取用于记录投诉和建议的信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('business:suggestions:query')")
    @GetMapping(value = "/{suggestionsId}")
    public AjaxResult getInfo(@PathVariable("suggestionsId") Long suggestionsId) {
        return success(wsdSuggestionsService.selectWsdSuggestionsBySuggestionsId(suggestionsId));
    }


    /**
     * 回复记录投诉和建议的信息
     */
    @PreAuthorize("@ss.hasPermi('business:suggestions:edit')")
    @Log(title = "回复记录投诉和建议的信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody WsdSuggestions wsdSuggestions) {

        return toAjax(wsdSuggestionsService.updateWsdSuggestions(wsdSuggestions));
    }

    /**
     * 删除用于记录投诉和建议的信息
     */
    @PreAuthorize("@ss.hasPermi('business:suggestions:remove')")
    @Log(title = "用于记录投诉和建议的信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{suggestionsIds}")
    public AjaxResult remove(@PathVariable Long[] suggestionsIds)
    {
        return toAjax(wsdSuggestionsService.deleteWsdSuggestionsBySuggestionsIds(suggestionsIds));
    }

}
